# Program variables (DON'T DELETE!!!)
block_speed = -6 # controls how fast the pipes move across the stage
block_gap = 200 # controls the space between the top and bottom of each pipe
block_interval = 1 # controls how often a new pipe appears
gravity = 8 # controls how fast the sprite falls
flappiness = 5 # controls how much the sprite moves up
# Store and display score
score = 0
score_text = codesters.Text("Score: " + str(score), 100, 200, "yellow")
########################################################################
# ADD CODE BELOW THIS LINE #
########################################################################
stage.set_background("space")
stage.disable_all_walls()
sprite = codesters.Sprite("dinosaur")
sprite.set_size(0.4)
sprite.set_say_color("yellow")
sprite.say("TAP THE SPACE BAR TO GUIDE ME THROUGH THE BLOCKS!", 3)
sprite.go_to(-200, 0)
stage.set_gravity(gravity)
def space_bar():
sprite.jump(flappiness)
stage.event_key("space", space_bar)
def interval():
global score
score += 1
score_text.set_text("Score: " + str(score))
make_blocks()
stage.event_interval(interval, block_interval)
def make_blocks():
pass # delete after adding indented code
y1 = random.randint(-250, -100)
# sprite = codesters.Rectangle(x, y, width, height, "color")
sprite = codesters.Rectangle(250, y1, 100, 300, "red")
sprite.set_gravity_off()
sprite.set_x_speed(block_speed)
y2 = y1 + 150 + block_gap + 150
# sprite = codesters.Rectangle(x, y, width, height, "color")
sprite = codesters.Rectangle(250, y2, 100, 300, "red")
sprite.set_gravity_off()
sprite.set_x_speed(block_speed)
t = codesters.Teacher()
defs = t.find_block("def")
go_tos = t.find_function("go_to")
hides = t.find_function("hide")
set_physics_off = t.find_function("set_physics_off")
try:
tval1 = defs[3][1].lower().replace(' ','')
tval1_indent = t.get_indent_at_line(defs[3][0])
except:
tval1 = "DNE"
tval1_indent = "DNE"
try:
tval2 = go_tos[1][1].lower().replace(' ','')
tval2_indent = t.get_indent_at_line(go_tos[1][0])
except:
tval2 = "DNE"
tval2_indent = "DNE"
try:
tval3 = hides[0][1].lower().replace(' ','')
tval3_indent = t.get_indent_at_line(hides[0][0])
except:
tval3 = "DNE"
tval3_indent = "DNE"
try:
tval4 = set_physics_off[0][1].lower().replace(' ','')
tval4_indent = t.get_indent_at_line(set_physics_off[0][0])
except:
tval4 = "DNE"
tval4_indent = "DNE"
t1 = TestObjective()
t1.add_success('defcollision(sprite,hit_sprite):' in tval1 and tval1_indent == 0, "Great Job!")
t1.add_failure(tval1 == "DNE", "Did you add a Collision event?")
t1.add_failure(tval1 != "DNE" and 'defcollision(sprite,hit_sprite):' not in tval1, "Are you sure you added a collision event?")
t1.add_failure(tval1 != "DNE" and tval1_indent != 0, "Make sure the collision event is not indented at all!")
t2 = TestObjective()
t2.add_success(tval2 == "DNE", "Great job!")
t2.add_failure(tval2 != "DNE", "Did you delete the .go_to() command from inside the collision event?")
t3 = TestObjective()
t3.add_success(tval3 == "DNE", "Great job!")
t3.add_failure(tval3 != "DNE", "Did you delete the .hide() command from inside the collision event?")
t4 = TestObjective()
t4.add_success(tval4 != "DNE" and tval4_indent == 4, "Great job!")
t4.add_failure(tval4 == "DNE", "Did you add Sprite Physics Off inside the collision event?")
t4.add_failure(tval4 != "DNE" and tval4_indent != 4, "Make sure Sprite Physics Off is indented once inside the collision event!")
tester = TestManager()
tester.add_test_list([t1, t2, t3, t4])
tester.run_tests()
tester.display_first_feedback()